<?php
namespace Acme\DemoBundle\FM\Classes;
class Folder{
private $name;
public $path;
private $size;
private $modifyDate;
private $files=array();
private $folders=array();
private $fileCount=0;
private $folderCount=0;
private $isexists=false;
	public function __construct($folder)
	{
		if(file_exists($folder)){
				if(round(filesize($folder)/1024/1024)!=0)
					$this->size=round(filesize($folder)/1024/1024)." MB";
				else if(round(filesize($folder)/1024)!=0)
					$this->size=round(filesize($folder)/1024)." KB";
				else 
					$this->size=filesize($folder)." B";
				$this->modifyDate=date("d/m/Y",filemtime($folder));
				$this->path=dirname($folder)."/";
				$this->name=substr($folder,strlen($this->path));
				$f=glob($folder."*.*");
				foreach($f as $fn)
				{
					$this->files[]=new File($fn);
					$this->fileCount+=1;
				}
				$f1=scandir($folder);
				foreach($f1 as $fn)
				{
				if($fn==".." or $fn==".") continue;
					if(is_dir($folder.$fn)){
					$this->folders[]=new Folder($folder.$fn);
					$this->folderCount+=1;
					}
				}
				
				$this->isexists=true;
		}
	}
	public function getFiles()
	{return $this->files;}
	public function getFolders()
	{return $this->folders;}
	public function filesCount()
	{return count($this->files);}
	public function foldersCount()
	{return count($this->folders);}
	public function isExists()
	{
		return $this->isexists;
	}
	public function getName()
	{return $this->name;}
	public function getSize()
	{return $this->size;}
	public function getModifyDate()
	{return $this->modifyDate;}
	public function delete()
	{
		rmdir($this->path.$this->name);
	}
	public function rename($name)
	{
		rename($this->path.$this->name,$this->path.$name);
		$this->name=$name;
	}
	
}
?>